<script type="text/javascript">
	$(document).ready(function() {
		$(".messageControl").hide();
		$(".messageBlock").mouseover(function() {
			$(this).children().children(".messageControl").show();
		});
		$(".messageBlock").mouseout(function() {
			$(this).children().children(".messageControl").hide();
		});
	});

	$(".messageEdit").each(function(){
		id = $(this).attr("id");
		
	});
		
</script>

<?php
    $jsShowMessageCategory = "
        function ShowMessageCategory(messageCategoryId){
            $(\".messageBlock\").hide();
            $(\".messageBlock-\"+messageCategoryId).show();
            return false;
        }
    ";
    Yii::app()->clientScript->registerScript('ShowMessageCategory',$jsShowMessageCategory,CClientScript::POS_HEAD);
    $pid = Yii::app()->request->getParam('pid');
?>
<div class="clear"></div>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->theme->baseUrl; ?>/css/message.css" />
<div id="than">	
           	 <img src="<?php echo Html::imageUrl("muiten.png");?>" width="27" height="26"; style="float:left">
            	<div id="textxanhdam">Message </div>
                 
		
      </div>
             <div class="padding15"></div>                    	
            	<!-- Begin leftSidebar-->                  
              	<div id="leftSidebar">
					<div id="leftWrapper">              	
						<button type="button">Add a message</button>
						<div class="padding20"></div>
						<h3>Category</h3>
						<ul>
							<!-- List messages category here -->
                                                        <li onclick="javascript:$('.messageBlock').show();">All Category</li>
                                                            <?php 
                                                                foreach ($messageCategories as $messageCategory){
                                                            ?>
                                                                    <li onclick="javascript:ShowMessageCategory(<?php echo $messageCategory['model']->message_category_id?>)"><?php echo $messageCategory['model']->message_category_name?></li>
                                                            <?php
                                                                }
                                                            ?>
                                                        <!-- End list messages category -->
						</ul>
					</div>
				<!-- End leftSidebar-->
				</div>
				
                <!-- Begin rightSidebar-->
               	<div  id="rightSidebar">                      
					<div id="rightHeader">
						<h2>Messages<h2>
						<button type="button" id="rightHeaderBtn" onclick="javascript:window.location ='<?php echo Yii::app()->controller->createUrl("/messages/addMessage/",array("pid"=>$pid));?>'">Add a message</button>
					</div>
					
					<div id="rightWrapper">
                                                <?php
                                                    
                                                    foreach ($messageCategories as $messageCategory){
                                                        $messageCategoryModel = $messageCategory['model'];
                                                        foreach ($messageCategory['listMessages'] as $message){
                                                        	$mid = $message->message_id;
                                                ?>
                                                            <!-- Start Loop -->
                                                            <div class="messageBlock messageBlock-<?php echo $messageCategoryModel->message_category_id ?>" id='messageBlock-<?php echo $mid?>'">
                                                                    <div class="blockHeader">
                                                                            <img class="message" src="<?php echo Html::imageUrl("message.png");?>" />
                                                                            <a href="<?php echo $this->createUrl("/messages/view",array("pid"=>$pid,"mid"=>$message->message_id));?>" class="messageLink"><?php echo $message->message_subject; ?></a>
                                                                            <font color="grey" size="2px"> in category </font>
                                                                            " <?php echo CHtml::link($messageCategoryModel->message_category_name, "#",array(
                                                                            	'class'=>"messageCategory",
                                                                            	'onclick'=>"ShowMessageCategory({$messageCategoryModel->message_category_id})",
                                                                            ))?>"
                                                                            <div class="messageControl">
                                                                            	<?php 
                                                                            		echo Chtml::link("Edit", $this->createUrl("/messages/edit",array('pid'=>$pid, 'mid'=>$mid)),
                                                                            			array(
                                                                            				'class'=>'messageEdit',
                                                                            			)
                                                                            		);
                                                                            		echo " | ";
                                                                            		echo Chtml::ajaxLink("Delete", $this->createUrl("/messages/del",array('mid'=>$message->message_id)), 
                                                                            			array(
                                                                            				'beforeSend'=>'function() {
                                                                            					return confirm("Are you sure");
                                                                            				}',
                                                                            				'data'=>array(
                                                                            					'mid'=>$message->message_id,
                                                                            				),
                                                                            				'success'=>"function(data){
																								$('#messageBlock-$mid').fadeOut('slow');
																								$('#messageBlock-$mid').remove();
																							}",
                                                                            			), 
                                                                            			array(
                                                                            				'class'=>'messageDelete',
                                                                            			)
                                                                            		);
                                                                            	?>
                                                                            </div>
                                                                    </div>
                                                                    <div class="replyBar">
                                                                            <?php
                                                                                $comments = $message->messageComments();
                                                                                $countComment = count($comments);
                                                                                if ($countComment != 0){
                                                                            ?>
                                                                                    <div class="replyText">
                                                                                        <font style="font-weight:bold;"><?php echo $countComment;?> Replies</font>
                                                                                        <a href="#" class="lastReply" >Last reply</a> by 
                                                                                        <a href="#" class="messageAuthor" ><?php echo $comments[$countComment-1]->commentPostedByUser->user_name; ?></a>
                                                                                        <?php echo $comments[$countComment-1]->spaceTime(); ?>
                                                                                    </div>
                                                                            <?php
                                                                                }
                                                                            ?>
                                                                    </div>
                                                                    <div class="blockMain">
                                                                            <div class="userInfo">
                                                                                    <img class="avatar" src="<?php echo Html::imageUrl("a3.png");?>" />
                                                                                    <div class="userName">	
                                                                                            <a href="#"><?php echo $message->messageSentByUser->user_name?></a> <br />
                                                                                            <font color="grey" size="1.5px">
                                                                                                    <?php echo Html::formatDate($message->message_sent_date) ?><br />
                                                                                                    <?php echo Html::formatTime($message->message_sent_date) ?>
                                                                                            </font>
                                                                                    </div>
                                                                                    
                                                                            </div>

                                                                            <div class="messageContent">
                                                                                    <?php echo $message->message_content;?>
                                                                                    <br />
                                                                                    <a href="<?php echo $this->createUrl("/messages/view",array("pid"=>$pid,"mid"=>$message->message_id));?>" class="viewLink">View this message and all responses</a>
                                                                            </div>

                                                                    </div>




                                                            </div>
                                                            <div class="padding5"></div>
                                                            <!-- End 1 loop -->
                                            <?php
                                                    }
                                                }
                                            ?>
					</div>
				<!-- Kết Thúc Cột Phải-->	
                </div>
                
                    
             </div>    
            
    <!--Kết thúc Phần Thân Nội Dung-->
